package com.hcb.micro.controller;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hcb.micro.controller.base.BaseControllers;
import com.hcb.micro.dto.AccountPlatform;
import com.hcb.micro.dto.Category;
import com.hcb.micro.dto.Mall;
import com.hcb.micro.dto.Manager;
import com.hcb.micro.dto.Product;
import com.hcb.micro.dto.ProductColor;
import com.hcb.micro.dto.ProductCount;
import com.hcb.micro.dto.ProductFormatPrice;
import com.hcb.micro.dto.ProductMall;
import com.hcb.micro.dto.ProductProcessingMethods;
import com.hcb.micro.dto.ProductReward;
import com.hcb.micro.dto.ProductSeller;
import com.hcb.micro.dto.ProductSize;
import com.hcb.micro.dto.ProductStyle;
import com.hcb.micro.dto.Union;
import com.hcb.micro.service.ICategoryService;
import com.hcb.micro.service.IMallService;
import com.hcb.micro.service.IProductColorService;
import com.hcb.micro.service.IProductCountService;
import com.hcb.micro.service.IProductFormatPriceService;
import com.hcb.micro.service.IProductMallService;
import com.hcb.micro.service.IProductProcessingMethodsService;
import com.hcb.micro.service.IProductRewardService;
import com.hcb.micro.service.IProductSellerService;
import com.hcb.micro.service.IProductService;
import com.hcb.micro.service.IProductSizeService;
import com.hcb.micro.service.IProductStyleService;
import com.hcb.micro.service.IProductSummaryService;
import com.hcb.micro.service.IQqbsAccountService;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("product")
public class ProductController extends BaseControllers{

	@Autowired
	IQqbsAccountService qqbsAccountService;
	
	@Autowired
	IMallService mallService;
	
	@Autowired
	IProductService productService;
	
	@Autowired
	IProductMallService productMallService;
		
	@Autowired
	IProductRewardService productRewardService;
	
	@Autowired
	IProductSellerService productSellerService;
	
	@Autowired
	IProductCountService productCountService;
	
	@Autowired
	ICategoryService categoryService;
	
	@Autowired
	IProductColorService productColorService;
	
	@Autowired
	IProductProcessingMethodsService productProcessingMethodsService;
	
	@Autowired
	IProductStyleService productStyleService;
	
	@Autowired
	IProductSizeService productSizeService;
	
	@Autowired
	IProductFormatPriceService productFormatPriceService;
	
	@Autowired
	IProductSummaryService productSummaryService;
	
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	public String list() throws FileNotFoundException, IOException {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		List<Product> productList = new ArrayList<>(),productListAll = new ArrayList<>();
		Map<String,Object> para = new HashMap<>();
		
		if(manager.getType() == 3){
			para.put("productSellerId", manager.getProductSellerId());
		}
		
		if (bodyInfo.get("productId") != null && !"".equals(bodyInfo.get("productId"))) {
			para.put("productId", bodyInfo.getString("productId"));
		}
		if (bodyInfo.get("name") != null && !"".equals(bodyInfo.get("name"))) {
			para.put("name", bodyInfo.getString("name"));
		}
		int count = 0;
			
		productListAll = productService.selectByPara(para);
		count = productListAll.size();
		
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			para.put("start", (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
			para.put("size", Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		productList = productService.selectByPara(para);
		if(productList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商品列表不存在");
			return buildReqJsonObject(json);
		}
		List<Map<String,String>> list = new ArrayList<>();
		for(Product product:productList){
			Map<String,String> map = new HashMap<>();
			Mall orderMall = mallService.selectByMallUuid(product.getMallUuid());
			
			map.put("id", product.getId()+"");
			map.put("orderNumber", product.getOrderNumber()+"");
			map.put("image1", product.getImage1()+"");
			if(orderMall == null){
				map.put("mallName", "商盟惠购商城");
			}else{
				map.put("mallName", orderMall.getMallName()+"商城");
			}
			if(product.getType() == 0){
				map.put("type", "普通商品");
			}else{
				map.put("type", "套餐商品");
			}
			map.put("name", product.getName()+"");
			
			Category category = categoryService.selectByPrimaryKey(product.getCategoryId());
			if(category == null){
				map.put("categoryName", "");
			}else{
				map.put("categoryName", category.getName()+"");
			}
			ProductSeller ps = productSellerService.selectByPrimaryKey(product.getProductSellerId());
			if(ps == null){
				map.put("productSellerName", "");
			}else{
				map.put("productSellerName", ps.getName()+"");
			}
			map.put("isUndertake", product.getIsUndertake()+"");
			map.put("salesPrice", product.getSalesPrice()+"");
			map.put("marketPrice", product.getMarketPrice()==null?"0":product.getMarketPrice()+"");
			map.put("createTime", product.getCreateTime()==null?"":sdf.format(product.getCreateTime()));
			
			list.add(map);
		}
		
    	json.put("result", "0");
		json.put("description", "获取商品列表成功");
		json.put("list", list);
		json.put("count", count);
		return buildReqJsonObject(json);
	}

	@RequestMapping(value = "detail", method = RequestMethod.POST)
	@ResponseBody
	public String detail() throws IOException {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		ProductReward productReward = productRewardService.selectByProductId(product.getId());
		Map<String,Object> map = new HashMap<>();
		map.put("id", product.getId()+"");
		if(product.getType() == 0){
			map.put("type", "普通商品");
		}else{
			map.put("type", "套餐商品");
		}
		map.put("productType", product.getType());
		List<String> imageList = new ArrayList<>();
		
		if(product.getImage1() != null && !"".equals(product.getImage1())){
			imageList.add(product.getImage1());
		}
		if(product.getImage2() != null && !"".equals(product.getImage2())){
			imageList.add(product.getImage2());
		}
		if(product.getImage3() != null && !"".equals(product.getImage3())){
			imageList.add(product.getImage3());
		}
		if(product.getImage4() != null && !"".equals(product.getImage4())){
			imageList.add(product.getImage4());
		}
		map.put("imageList", imageList);
		map.put("desc", product.getDesc());
		map.put("remark", product.getRemark()==null?"":product.getRemark());
		map.put("shortName", product.getShortName());
		map.put("sellingPoint", product.getSellingPoint());
		
		map.put("netVolume", product.getNetVolume()==null?"":product.getNetVolume());
		map.put("placeOfOrigin", product.getPlaceOfOrigin()==null?"":product.getPlaceOfOrigin());
		map.put("manufacturerDate", product.getManufacturerDate()==null?"":product.getManufacturerDate());
		map.put("storageMethod", product.getStorageMethod()==null?"":product.getStorageMethod());
		map.put("durabilityPeriod", product.getDurabilityPeriod()==null?"":product.getDurabilityPeriod());
		map.put("peopleFor", product.getPeopleFor()==null?"":product.getPeopleFor());
		map.put("useMethod", product.getUseMethod()==null?"":product.getUseMethod());
		map.put("brandName", product.getBrandName()==null?"":product.getBrandName());
		map.put("textureName", product.getTextureName()==null?"":product.getTextureName());
		map.put("shadingIndex", product.getShadingIndex()==null?"":product.getShadingIndex());
		map.put("thicknessIndex", product.getThicknessIndex()==null?"":product.getThicknessIndex());
		map.put("sagIndex", product.getSagIndex()==null?"":product.getSagIndex());
		map.put("cottonsTechnics", product.getCottonsTechnics()==null?"":product.getCottonsTechnics());
		map.put("yarnTechnics", product.getYarnTechnics()==null?"":product.getYarnTechnics());
		map.put("styleName", product.getStyleName()==null?"":product.getStyleName());
		map.put("weightOfCloth", product.getWeightOfCloth()==null?"":product.getWeightOfCloth());
		map.put("weightOfYarn", product.getWeightOfYarn()==null?"":product.getWeightOfYarn());
		map.put("washingMethod", product.getWashingMethod()==null?"":product.getWashingMethod());
		
		map.put("nuoaUrl", product.getNuoaUrl()==null?"":product.getNuoaUrl());
		map.put("certificateNumber", product.getCertificateNumber()==null?"":product.getCertificateNumber());
		map.put("formatImage", product.getFormatImage()==null?"":product.getFormatImage());
		map.put("image5", product.getImage5()==null?"":product.getImage5());
		map.put("orderNumber", product.getOrderNumber()==null?"":product.getOrderNumber());
		map.put("startTime", product.getStartTime()==null?"":sdf.format(product.getStartTime()));
		map.put("endingTime", product.getEndTime()==null?"":sdf.format(product.getEndTime()));
		
		//商品详情图片拆分展示
		
		map.put("content",product.getPcDetail());
		map.put("name", product.getName()+"");
		map.put("salesPrice", product.getSalesPrice()+"");
		map.put("marketPrice", product.getMarketPrice()==null?"0":product.getMarketPrice());
		map.put("createTime", product.getCreateTime()==null?"":sdf.format(product.getCreateTime()));
		
		ProductCount pc = productCountService.selectByProductId(product.getId());
		map.put("stock", pc.getStock()+"");
		map.put("stockAlgorithm", pc.getStockAlgorithm()+"");
		
		String partnerReward = null;
		String partnerReward2 = null;
		String shopReward = null;
		String shopReward2 = null;
		String saleReward = null;
		String nomalReward = null;
		String nomalReward2 = null;
		String backPercent = null;
		String uplevelPrice = null;
		String uplevelPercent = null;
		//List<Map<String,String>> list = new ArrayList<>();
		if(productReward != null){
			/*platformReward = productReward.getPlatformReward()+"";
			backPercent=productReward.getBackPercent()+"";
			String[] rewardList = productReward.getAccountRewardlist().split(",");
			String[] rewardList2 = productReward.getAccountRewardlist2().split(",");
			String[] rewardTime = productReward.getAccountRewardtime().split(",");
			for(int i = 0;i<rewardList.length;i++){
				Map<String,String> reward = new HashMap<>();
				reward.put("rewardList", Float.valueOf(rewardList[i])+"");
				reward.put("rewardList2", Float.valueOf(rewardList2[i])+"");
				reward.put("rewardTime", rewardTime[i]);
				list.add(reward);
			}*/
			
			partnerReward = productReward.getPartnerReward()+"";
			partnerReward2 = productReward.getPartnerReward2()+"";
			shopReward = productReward.getShopReward()+"";
			shopReward2 = productReward.getShopReward2()+"";
			saleReward = productReward.getSaleReward()+"";
			nomalReward = productReward.getNomalReward()+"";
			nomalReward2 = productReward.getNomalReward2()+"";
			backPercent = productReward.getBackPercent()+"";
			uplevelPrice = productReward.getUplevelPrice()+"";
			uplevelPercent = productReward.getUplevelPercent()+"";
			
			map.put("partnerReward", Float.valueOf(partnerReward)+"");
			map.put("partnerReward2", Float.valueOf(partnerReward2)+"");
			map.put("shopReward", Float.valueOf(shopReward)+"");
			map.put("shopReward2", Float.valueOf(shopReward2)+"");
			map.put("saleReward", Float.valueOf(saleReward)+"");
			map.put("nomalReward", Float.valueOf(nomalReward)+"");
			map.put("nomalReward2", Float.valueOf(nomalReward2)+"");
			map.put("backPercent", Float.valueOf(backPercent)+"");
			map.put("uplevelPrice", Float.valueOf(uplevelPrice)+"");
			map.put("uplevelPercent", Float.valueOf(uplevelPercent)+"");
		}
		
		//商城列表
		Mall mall = mallService.selectByMallUuid(manager.getMallUuid());
        Map<String,Object> para = new HashMap<>();
		if(mall != null && !"商盟惠购".equals(mall.getMallName())){
			para.put("mallUuid", mall.getMallUuid());
		}
		List<Mall> mallList = mallService.selectByPara(para);
        List<Map<String,Object>> list2 = new ArrayList<>();
        for (Mall m: mallList)
        {	
        	Map<String,Object> mallmap = new HashMap<>();
        	para.put("productId", product.getId());
        	para.put("mallUuid", m.getMallUuid());
        	List<ProductMall> pmList = productMallService.selectByPara(para);
        	if(pmList.size()>0){
        		mallmap.put("hava", 1);
        	}else{
        		mallmap.put("hava", 0);
        	}
        	if("hdnksdftu123bzz".equals(m.getMallUuid())){
        		mallmap.put("hava", 1);
        	}
        	mallmap.put("mallUuid", m.getMallUuid());
        	mallmap.put("mallName", m.getMallName());
        	list2.add(mallmap);
        }
        map.put("mallList", list2);
		
        //供应商列表
        Map<String,Object> para2 = new HashMap<>();
		List<ProductSeller> productSellerAllList = productSellerService.selectAllByPara(para2);
		List<Map<String,Object>> list3 = new ArrayList<>();
		for (ProductSeller productSeller: productSellerAllList)
        {	
        	Map<String,Object> psmap = new HashMap<>();
        	ProductSeller ps = productSellerService.selectByPrimaryKey(product.getProductSellerId());
        	if(ps == null){
        		psmap.put("hava", 0);
        	}else{
        		if(ps.getId() == productSeller.getId()){
        			psmap.put("hava", 1);
        		}else{
        			psmap.put("hava", 0);
        		}
        	}

        	psmap.put("productSellerId", productSeller.getId());
        	psmap.put("productSellerName", productSeller.getName());
        	list3.add(psmap);
        }
        map.put("productSellerList", list3);
        
        //分类列表
        Map<String,Object> para4 = new HashMap<>();
		List<Category> categoryList = categoryService.selectAllByPara(para4);
		List<Map<String,Object>> list4 = new ArrayList<>();
		for(Category category:categoryList){
			Map<String,Object> cmap = new HashMap<>();
			if(category.getId() == product.getCategoryId()){
				cmap.put("hava", 1);
    		}else{
    			cmap.put("hava", 0);
    		}
			cmap.put("id", category.getId()+"");
			cmap.put("name", category.getName()+"");
			cmap.put("desc", category.getDesc()==null?"":category.getDesc());
			list4.add(cmap);
		}
		map.put("categoryList", list4);
        
		json.put("result", "0");
		json.put("description", "获取商品信息成功");
		json.put("product", map);
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "modify", method = RequestMethod.POST)
	@ResponseBody
	public String modify() throws ParseException {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		net.sf.json.JSONArray saleAreaList = bodyInfo.getJSONArray("saleAreaList");
		//net.sf.json.JSONArray rewardList = bodyInfo.getJSONArray("rewardList");
		//net.sf.json.JSONArray rewardList2 = bodyInfo.getJSONArray("rewardList2");
		//net.sf.json.JSONArray rewardTime = bodyInfo.getJSONArray("rewardTime");
		
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}else if(bodyInfo.get("name") == null || "".equals(bodyInfo.get("name"))){
			right = 0;
		}else if(bodyInfo.get("salesPrice") == null || "".equals(bodyInfo.get("salesPrice"))){
			right = 0;
		}else if(bodyInfo.get("productType") == null || "".equals(bodyInfo.get("productType"))){
			right = 0;
		}else if(bodyInfo.get("productSeller") == null || "".equals(bodyInfo.get("productSeller"))){
			right = 0;
		}else if(bodyInfo.get("productCategory") == null || "".equals(bodyInfo.get("productCategory"))){
			right = 0;
		}/*else if(bodyInfo.get("platformReward") == null || "".equals(bodyInfo.get("platformReward"))){
			right = 0;
		}else if(bodyInfo.get("backPercent") == null || "".equals(bodyInfo.get("backPercent"))){
			right = 0;
		}*/else if(bodyInfo.get("desc") == null || "".equals(bodyInfo.get("desc"))){
			right = 0;
		}else if(bodyInfo.get("shortName") == null || "".equals(bodyInfo.get("shortName"))){
			right = 0; 
		}else if(bodyInfo.get("sellingPoint") == null || "".equals(bodyInfo.get("sellingPoint"))){
			right = 0; 
		}else if(bodyInfo.get("imageList") == null || "".equals(bodyInfo.get("imageList"))){
			right = 0;
		}else if(bodyInfo.get("content") == null || "".equals(bodyInfo.get("content"))){
			right = 0;
		}else if(bodyInfo.get("startTime") == null || "".equals(bodyInfo.get("startTime"))){
			right = 0;
		}else if(bodyInfo.get("endingTime") == null || "".equals(bodyInfo.get("endingTime"))){
			right = 0;
		}else if(saleAreaList.size() == 0 || saleAreaList == null) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		//查看是否更改了商品价格，如果更改商品价格，则插入商品价格记录
		int checkNum=0;
		if(!product.getSalesPrice().equals(Float.valueOf(bodyInfo.getString("salesPrice")))){
			checkNum=1;
		}

		product.setName(bodyInfo.getString("name"));
		product.setSalesPrice(Float.valueOf(bodyInfo.getString("salesPrice")));
		if(bodyInfo.get("marketPrice") != null && !"".equals(bodyInfo.get("marketPrice"))){
			product.setMarketPrice(Float.valueOf(bodyInfo.getString("marketPrice")));
		}
		product.setCategoryId(Integer.valueOf(bodyInfo.getString("productCategory")));
		
		if(manager.getType() != 1 && "1".equals(bodyInfo.getString("productType"))){
			json.put("result", "1");
			json.put("description", "该账号无权限设置套餐");
			return buildReqJsonObject(json);
		}
		product.setType(Byte.valueOf(bodyInfo.getString("productType")));
		product.setDesc(bodyInfo.getString("desc"));
		product.setShortName(bodyInfo.getString("shortName"));
		product.setSellingPoint(bodyInfo.getString("sellingPoint"));
		
		if(bodyInfo.get("netVolume") != null && !"".equals(bodyInfo.get("netVolume"))){
			product.setNetVolume(bodyInfo.getString("netVolume"));
		}
		if(bodyInfo.get("placeOfOrigin") != null && !"".equals(bodyInfo.get("placeOfOrigin"))){
			product.setPlaceOfOrigin(bodyInfo.getString("placeOfOrigin"));
		}
		if(bodyInfo.get("manufacturerDate") != null && !"".equals(bodyInfo.get("manufacturerDate"))){
			product.setManufacturerDate(bodyInfo.getString("manufacturerDate"));
		}
		if(bodyInfo.get("storageMethod") != null && !"".equals(bodyInfo.get("storageMethod"))){
			product.setStorageMethod(bodyInfo.getString("storageMethod"));
		}
		if(bodyInfo.get("durabilityPeriod") != null && !"".equals(bodyInfo.get("durabilityPeriod"))){
			product.setDurabilityPeriod(bodyInfo.getString("durabilityPeriod"));
		}
		if(bodyInfo.get("peopleFor") != null && !"".equals(bodyInfo.get("peopleFor"))){
			product.setPeopleFor(bodyInfo.getString("peopleFor"));
		}
		if(bodyInfo.get("useMethod") != null && !"".equals(bodyInfo.get("useMethod"))){
			product.setUseMethod(bodyInfo.getString("useMethod"));
		}
		
		if(bodyInfo.get("remark") != null && !"".equals(bodyInfo.get("remark"))){
			product.setRemark(bodyInfo.getString("remark"));
		}
		if("".equals(bodyInfo.get("remark"))){
			product.setRemark(null);
		}
		if(bodyInfo.get("brandName") != null && !"".equals(bodyInfo.get("brandName"))){
			product.setBrandName(bodyInfo.getString("brandName"));
		}
		if(bodyInfo.get("textureName") != null && !"".equals(bodyInfo.get("textureName"))){
			product.setTextureName(bodyInfo.getString("textureName"));
		}
		if(bodyInfo.get("shadingIndex") != null && !"".equals(bodyInfo.get("shadingIndex"))){
			product.setShadingIndex(bodyInfo.getString("shadingIndex"));
		}
		if(bodyInfo.get("thicknessIndex") != null && !"".equals(bodyInfo.get("thicknessIndex"))){
			product.setThicknessIndex(bodyInfo.getString("thicknessIndex"));
		}
		if(bodyInfo.get("sagIndex") != null && !"".equals(bodyInfo.get("sagIndex"))){
			product.setSagIndex(bodyInfo.getString("sagIndex"));
		}
		if(bodyInfo.get("cottonsTechnics") != null && !"".equals(bodyInfo.get("cottonsTechnics"))){
			product.setCottonsTechnics(bodyInfo.getString("cottonsTechnics"));
		}
		if(bodyInfo.get("yarnTechnics") != null && !"".equals(bodyInfo.get("yarnTechnics"))){
			product.setYarnTechnics(bodyInfo.getString("yarnTechnics"));
		}
		if(bodyInfo.get("styleName") != null && !"".equals(bodyInfo.get("styleName"))){
			product.setStyleName(bodyInfo.getString("styleName"));
		}
		if(bodyInfo.get("weightOfCloth") != null && !"".equals(bodyInfo.get("weightOfCloth"))){
			product.setWeightOfCloth(bodyInfo.getString("weightOfCloth"));
		}
		if(bodyInfo.get("weightOfYarn") != null && !"".equals(bodyInfo.get("weightOfYarn"))){
			product.setWeightOfYarn(bodyInfo.getString("weightOfYarn"));
		}
		if(bodyInfo.get("washingMethod") != null && !"".equals(bodyInfo.get("washingMethod"))){
			product.setWashingMethod(bodyInfo.getString("washingMethod"));
		}
		
		if(manager.getType() != 1 && "1".equals(bodyInfo.getString("productType"))){
			product.setOrderNumber(999);
		}else{
			if(bodyInfo.get("orderNumber") != null && !"".equals(bodyInfo.get("orderNumber"))){
				product.setOrderNumber(Integer.valueOf(bodyInfo.getString("orderNumber")));
			}
		}
		
		if(bodyInfo.get("nuoaUrl") != null && !"".equals(bodyInfo.get("nuoaUrl"))){
			product.setNuoaUrl(bodyInfo.getString("nuoaUrl"));
		}
		if(bodyInfo.get("formatImage") != null && !"".equals(bodyInfo.get("formatImage"))){
			product.setFormatImage(bodyInfo.getString("formatImage"));
		}
		if(bodyInfo.get("image5") != null && !"".equals(bodyInfo.get("image5"))){
			product.setImage5(bodyInfo.getString("image5"));
		}
		if(bodyInfo.get("certificateNumber") != null && !"".equals(bodyInfo.get("certificateNumber"))){
			product.setCertificateNumber(bodyInfo.getString("certificateNumber"));
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		product.setStartTime(sdf.parse(bodyInfo.getString("startTime")));
		product.setEndTime(sdf.parse(bodyInfo.getString("endingTime")));
		
		product.setPcDetail(bodyInfo.getString("content"));
		
		//更新库存，限购数量
		boolean isUpdatePC = false;
		ProductCount pc = productCountService.selectByProductId(product.getId());
		if(bodyInfo.get("stock") != null && !"".equals(bodyInfo.get("stock"))){
			pc.setStock(Integer.valueOf(bodyInfo.getString("stock")));
			isUpdatePC = true;
		}
		if(bodyInfo.get("stockAlgorithm") != null && !"".equals(bodyInfo.get("stockAlgorithm"))){
			pc.setStockAlgorithm(Byte.valueOf(bodyInfo.getString("stockAlgorithm")));
			isUpdatePC = true;
		}
		if(isUpdatePC){
			Integer updatePC = productCountService.updateByPrimaryKeySelective(pc);
			if(updatePC == 0){
				json.put("result", "1");
				json.put("description", "更新商品库存，限购数量出错");
				return buildReqJsonObject(json);
			}
		}
		
		ProductSeller ps = productSellerService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productSeller")));
		if(ps == null){
			json.put("result", "1");
			json.put("description", "供应商不存在");
			return buildReqJsonObject(json);
		}else{
			product.setProductSellerId(ps.getId());
		}
		
		String[] imageList = bodyInfo.getString("imageList").split(",");
		for(int i=0;i<imageList.length;i++){
			if(i==0){
				product.setImage1(imageList[i]);
			}else if(i==1){
				product.setImage2(imageList[i]);
			}else if(i==2){
				product.setImage3(imageList[i]);
			}else if(i==3){
				product.setImage4(imageList[i]);
			}
		}

		Integer updateProduct = productService.updateByPrimaryKeySelective(product);
		if(updateProduct == 1){
			System.out.println("---修改商品信息成功---");
			
			//查看是否更改了商品价格，如果更改商品价格，则插入商品价格记录
			if(checkNum==1){
				Map<String,Object> map=new HashMap<String,Object>();
				map.put("productId", product.getId());
				map.put("price", product.getSalesPrice());
				map.put("createTime", new Date());
				productService.insertProductLog(map);
			}
			
			ProductReward pr = productRewardService.selectByProductId(product.getId());
			/*//一级佣金比例
			String rewardListStr = "";
			for(int i=0;i<rewardList.size();i++){
				if(rewardList.get(i) != null){
					rewardListStr += rewardList.get(i).toString()+",";
				}
			}
			//二级佣金比例
			String rewardList2Str = "";
			for(int i=0;i<rewardList2.size();i++){
				if(rewardList2.get(i) != null){
					rewardList2Str += rewardList2.get(i).toString()+",";
				}
			}
			//佣金发放时间
			String rewardTimeStr = "";
			for(int i=0;i<rewardTime.size();i++){
				if(rewardTime.get(i) != null){
					rewardTimeStr += rewardTime.get(i).toString()+",";
				}
			}*/
			
			Integer prResult = 0;
			if(pr == null){
				pr = new ProductReward();
				pr.setProductId(product.getId());
				//pr.setPlatformReward(Float.valueOf(bodyInfo.getString("platformReward")));
				//pr.snt(Float.valueOf(bodyInfo.getString("backPercent")));
				
				if(bodyInfo.get("partnerReward") != null && !"".equals(bodyInfo.get("partnerReward"))){
					pr.setPartnerReward(Float.valueOf(bodyInfo.getString("partnerReward")));
				}
				if(bodyInfo.get("partnerReward2") != null && !"".equals(bodyInfo.get("partnerReward2"))){
					pr.setPartnerReward2(Float.valueOf(bodyInfo.getString("partnerReward2")));
				}
				if(bodyInfo.get("shopReward") != null && !"".equals(bodyInfo.get("shopReward"))){
					pr.setShopReward(Float.valueOf(bodyInfo.getString("shopReward")));
				}
				if(bodyInfo.get("shopReward2") != null && !"".equals(bodyInfo.get("shopReward2"))){
					pr.setShopReward2(Float.valueOf(bodyInfo.getString("shopReward2")));
				}
				if(bodyInfo.get("saleReward") != null && !"".equals(bodyInfo.get("saleReward"))){
					pr.setSaleReward(Float.valueOf(bodyInfo.getString("saleReward")));
				}
				if(bodyInfo.get("nomalReward2") != null && !"".equals(bodyInfo.get("nomalReward2"))){
					pr.setNomalReward2(Float.valueOf(bodyInfo.getString("nomalReward2")));
				}
				if(bodyInfo.get("nomalReward") != null && !"".equals(bodyInfo.get("nomalReward"))){
					pr.setNomalReward(Float.valueOf(bodyInfo.getString("nomalReward")));
				}
				if(bodyInfo.get("backPercent") != null && !"".equals(bodyInfo.get("backPercent"))){
					pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				}
				if(bodyInfo.get("uplevelPrice") != null && !"".equals(bodyInfo.get("uplevelPrice"))){
					pr.setUplevelPrice(Float.valueOf(bodyInfo.getString("uplevelPrice")));
				}
				if(bodyInfo.get("uplevelPercent") != null && !"".equals(bodyInfo.get("uplevelPercent"))){
					pr.setUplevelPercent(Float.valueOf(bodyInfo.getString("uplevelPercent")));
				}
				
				//pr.setAccountRewardlist(rewardListStr);
				//pr.setAccountRewardlist2(rewardList2Str);
				//pr.setAccountRewardtime(rewardTimeStr);
				prResult = productRewardService.insertSelective(pr);
				
			}else{
				pr.setProductId(product.getId());
				//pr.setPlatformReward(Float.valueOf(bodyInfo.getString("platformReward")));
				//pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				//pr.setAccountRewardlist(rewardListStr);
				//pr.setAccountRewardlist2(rewardList2Str);
				//pr.setAccountRewardtime(rewardTimeStr);
				
				if(bodyInfo.get("partnerReward") != null && !"".equals(bodyInfo.get("partnerReward"))){
					pr.setPartnerReward(Float.valueOf(bodyInfo.getString("partnerReward")));
				}
				if(bodyInfo.get("partnerReward2") != null && !"".equals(bodyInfo.get("partnerReward2"))){
					pr.setPartnerReward2(Float.valueOf(bodyInfo.getString("partnerReward2")));
				}
				if(bodyInfo.get("shopReward") != null && !"".equals(bodyInfo.get("shopReward"))){
					pr.setShopReward(Float.valueOf(bodyInfo.getString("shopReward")));
				}
				if(bodyInfo.get("shopReward2") != null && !"".equals(bodyInfo.get("shopReward2"))){
					pr.setShopReward2(Float.valueOf(bodyInfo.getString("shopReward2")));
				}
				if(bodyInfo.get("saleReward") != null && !"".equals(bodyInfo.get("saleReward"))){
					pr.setSaleReward(Float.valueOf(bodyInfo.getString("saleReward")));
				}
				if(bodyInfo.get("nomalReward2") != null && !"".equals(bodyInfo.get("nomalReward2"))){
					pr.setNomalReward2(Float.valueOf(bodyInfo.getString("nomalReward2")));
				}
				if(bodyInfo.get("nomalReward") != null && !"".equals(bodyInfo.get("nomalReward"))){
					pr.setNomalReward(Float.valueOf(bodyInfo.getString("nomalReward")));
				}
				if(bodyInfo.get("backPercent") != null && !"".equals(bodyInfo.get("backPercent"))){
					pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				}
				if(bodyInfo.get("uplevelPrice") != null && !"".equals(bodyInfo.get("uplevelPrice"))){
					pr.setUplevelPrice(Float.valueOf(bodyInfo.getString("uplevelPrice")));
				}
				if(bodyInfo.get("uplevelPercent") != null && !"".equals(bodyInfo.get("uplevelPercent"))){
					pr.setUplevelPercent(Float.valueOf(bodyInfo.getString("uplevelPercent")));
				}
				
				prResult = productRewardService.updateByPrimaryKeySelective(pr);
			}
			if(prResult == 0){
    			System.out.println("---新增或修改商品佣金比例失败---");
    			json.put("result", "1");
    			json.put("description", "新增或修改商品佣金比例失败");
    			return buildReqJsonObject(json);
    		}else{
    			System.out.println("---新增或修改商品销佣金比例成功---");
    		}
			
			Map<String,Object> para = new HashMap<>();
        	para.put("productId", product.getId());
    		List<ProductMall> pmList = productMallService.selectByPara(para);
    		if(pmList.size()>0){
    			for(ProductMall pm:pmList){
					Integer deletePM = productMallService.deleteByPrimaryKey(pm.getId());
	        		if(deletePM == 0){
	        			System.out.println("---删除商品销售范围失败---");
	        			json.put("result", "1");
	        			json.put("description", "删除商品销售范围失败");
	        			return buildReqJsonObject(json);
	        		}else{
	        			System.out.println("---删除商品销售范围成功---");
	        		}
        		}
    		}
			
			for(int i=0;i<saleAreaList.size();i++){
				if(saleAreaList.get(i) != null){
		        	Mall mall = mallService.selectByMallUuid(saleAreaList.get(i).toString());
	    			ProductMall pm = new ProductMall();
	        		pm.setMallUuid(mall.getMallUuid());
	        		pm.setProductId(product.getId());
	        		pm.setCreateTime(new Date());
	        		Integer insertPM = productMallService.insertSelective(pm);
	        		if(insertPM == 0){
	        			System.out.println("---新增商品销售范围失败---");
	        			json.put("result", "1");
	        			json.put("description", "新增商品销售范围失败");
	        			return buildReqJsonObject(json);
	        		}else{
	        			System.out.println("---新增商品销售范围成功---");
	        		}
				}
			}
		}else{
			json.put("result", "1");
			json.put("description", "修改商品信息失败");
			return buildReqJsonObject(json);
		}
		json.put("result", "0");
		json.put("description", "修改商品信息成功");
		return buildReqJsonObject(json);
	}
	
	
	@RequestMapping(value = "create", method = RequestMethod.POST)
	@ResponseBody
	public String create() throws ParseException {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		net.sf.json.JSONArray saleAreaList = bodyInfo.getJSONArray("saleAreaList");
		//net.sf.json.JSONArray rewardList = bodyInfo.getJSONArray("rewardList");
		//net.sf.json.JSONArray rewardList2 = bodyInfo.getJSONArray("rewardList2");
		//net.sf.json.JSONArray rewardTime = bodyInfo.getJSONArray("rewardTime");
		
		int right = 1;
		if(bodyInfo.get("name") == null || "".equals(bodyInfo.get("name"))){
			right = 0;
		}else if(bodyInfo.get("salesPrice") == null || "".equals(bodyInfo.get("salesPrice"))){
			right = 0; 
		}else if(bodyInfo.get("productType") == null || "".equals(bodyInfo.get("productType"))){
			right = 0; 
		}else if(bodyInfo.get("productSeller") == null || "".equals(bodyInfo.get("productSeller"))){
			right = 0; 
		}else if(bodyInfo.get("productCategory") == null || "".equals(bodyInfo.get("productCategory"))){
			right = 0;
		}/*else if(bodyInfo.get("platformReward") == null || "".equals(bodyInfo.get("platformReward"))){
			right = 0;
		}else if(bodyInfo.get("backPercent") == null || "".equals(bodyInfo.get("backPercent"))){
			right = 0; 
		}*/else if(bodyInfo.get("desc") == null || "".equals(bodyInfo.get("desc"))){
			right = 0; 
		}else if(bodyInfo.get("shortName") == null || "".equals(bodyInfo.get("shortName"))){
			right = 0; 
		}else if(bodyInfo.get("sellingPoint") == null || "".equals(bodyInfo.get("sellingPoint"))){
			right = 0; 
		}else if(bodyInfo.get("imageList") == null || "".equals(bodyInfo.get("imageList"))){
			right = 0; 
		}else if(bodyInfo.get("content") == null || "".equals(bodyInfo.get("content"))){
			right = 0; 
		}else if(bodyInfo.get("startTime") == null || "".equals(bodyInfo.get("startTime"))){
			right = 0;
		}else if(bodyInfo.get("endingTime") == null || "".equals(bodyInfo.get("endingTime"))){
			right = 0;
		}else if(saleAreaList.size() == 0 || saleAreaList == null) {
			right = 0; 
		}/*else if(rewardList.size() == 0 || rewardList == null) {
			right = 0; 
		}else if(rewardList2.size() == 0 || rewardList2 == null) {
			right = 0; 
		}else if(rewardTime.size() == 0 || rewardTime == null) {
			right = 0; 
		}*/
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Product product = new Product();
		product.setName(bodyInfo.getString("name"));
		product.setSalesPrice(Float.valueOf(bodyInfo.getString("salesPrice")));
		if(bodyInfo.get("marketPrice") != null && !"".equals(bodyInfo.get("marketPrice"))){
			product.setMarketPrice(Float.valueOf(bodyInfo.getString("marketPrice")));
		}
		
		if(manager.getType() != 1 && "1".equals(bodyInfo.getString("productType"))){
			product.setOrderNumber(999);
		}else{
			if(bodyInfo.get("orderNumber") != null && !"".equals(bodyInfo.get("orderNumber"))){
				product.setOrderNumber(Integer.valueOf(bodyInfo.getString("orderNumber")));
			}
		}
		if(bodyInfo.get("nuoaUrl") != null && !"".equals(bodyInfo.get("nuoaUrl"))){
			product.setNuoaUrl(bodyInfo.getString("nuoaUrl"));
		}
		if(bodyInfo.get("formatImage") != null && !"".equals(bodyInfo.get("formatImage"))){
			product.setFormatImage(bodyInfo.getString("formatImage"));
		}
		if(bodyInfo.get("image5") != null && !"".equals(bodyInfo.get("image5"))){
			product.setImage5(bodyInfo.getString("image5"));
		}
		if(bodyInfo.get("certificateNumber") != null && !"".equals(bodyInfo.get("certificateNumber"))){
			product.setCertificateNumber(bodyInfo.getString("certificateNumber"));
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		product.setStartTime(sdf.parse(bodyInfo.getString("startTime")));
		product.setEndTime(sdf.parse(bodyInfo.getString("endingTime")));
		
		product.setCategoryId(Integer.valueOf(bodyInfo.getString("productCategory")));
		
		if(manager.getType() != 1 && "1".equals(bodyInfo.getString("productType"))){
			json.put("result", "1");
			json.put("description", "该账号无权限设置套餐");
			return buildReqJsonObject(json);
		}
		
		product.setType(Byte.valueOf(bodyInfo.getString("productType")));
		product.setDesc(bodyInfo.getString("desc"));
		product.setShortName(bodyInfo.getString("shortName"));
		product.setSellingPoint(bodyInfo.getString("sellingPoint"));
		
		if(bodyInfo.get("netVolume") != null && !"".equals(bodyInfo.get("netVolume"))){
			product.setNetVolume(bodyInfo.getString("netVolume"));
		}
		if(bodyInfo.get("placeOfOrigin") != null && !"".equals(bodyInfo.get("placeOfOrigin"))){
			product.setPlaceOfOrigin(bodyInfo.getString("placeOfOrigin"));
		}
		if(bodyInfo.get("manufacturerDate") != null && !"".equals(bodyInfo.get("manufacturerDate"))){
			product.setManufacturerDate(bodyInfo.getString("manufacturerDate"));
		}
		if(bodyInfo.get("storageMethod") != null && !"".equals(bodyInfo.get("storageMethod"))){
			product.setStorageMethod(bodyInfo.getString("storageMethod"));
		}
		if(bodyInfo.get("durabilityPeriod") != null && !"".equals(bodyInfo.get("durabilityPeriod"))){
			product.setDurabilityPeriod(bodyInfo.getString("durabilityPeriod"));
		}
		if(bodyInfo.get("peopleFor") != null && !"".equals(bodyInfo.get("peopleFor"))){
			product.setPeopleFor(bodyInfo.getString("peopleFor"));
		}
		if(bodyInfo.get("useMethod") != null && !"".equals(bodyInfo.get("useMethod"))){
			product.setUseMethod(bodyInfo.getString("useMethod"));
		}
		
		if(bodyInfo.get("remark") != null && !"".equals(bodyInfo.get("remark"))){
			product.setRemark(bodyInfo.getString("remark"));
		}
		if(bodyInfo.get("brandName") != null && !"".equals(bodyInfo.get("brandName"))){
			product.setBrandName(bodyInfo.getString("brandName"));
		}
		if(bodyInfo.get("textureName") != null && !"".equals(bodyInfo.get("textureName"))){
			product.setTextureName(bodyInfo.getString("textureName"));
		}
		if(bodyInfo.get("shadingIndex") != null && !"".equals(bodyInfo.get("shadingIndex"))){
			product.setShadingIndex(bodyInfo.getString("shadingIndex"));
		}
		if(bodyInfo.get("thicknessIndex") != null && !"".equals(bodyInfo.get("thicknessIndex"))){
			product.setThicknessIndex(bodyInfo.getString("thicknessIndex"));
		}
		if(bodyInfo.get("sagIndex") != null && !"".equals(bodyInfo.get("sagIndex"))){
			product.setSagIndex(bodyInfo.getString("sagIndex"));
		}
		if(bodyInfo.get("cottonsTechnics") != null && !"".equals(bodyInfo.get("cottonsTechnics"))){
			product.setCottonsTechnics(bodyInfo.getString("cottonsTechnics"));
		}
		if(bodyInfo.get("yarnTechnics") != null && !"".equals(bodyInfo.get("yarnTechnics"))){
			product.setYarnTechnics(bodyInfo.getString("yarnTechnics"));
		}
		if(bodyInfo.get("styleName") != null && !"".equals(bodyInfo.get("styleName"))){
			product.setStyleName(bodyInfo.getString("styleName"));
		}
		if(bodyInfo.get("weightOfCloth") != null && !"".equals(bodyInfo.get("weightOfCloth"))){
			product.setWeightOfCloth(bodyInfo.getString("weightOfCloth"));
		}
		if(bodyInfo.get("weightOfYarn") != null && !"".equals(bodyInfo.get("weightOfYarn"))){
			product.setWeightOfYarn(bodyInfo.getString("weightOfYarn"));
		}
		if(bodyInfo.get("washingMethod") != null && !"".equals(bodyInfo.get("washingMethod"))){
			product.setWashingMethod(bodyInfo.getString("washingMethod"));
		}
		
		product.setPcDetail(bodyInfo.getString("content"));
		product.setCreateTime(new Date());
		
		ProductSeller ps = productSellerService.selectByPrimaryKey(bodyInfo.getInt("productSeller"));
		if(ps == null){
			json.put("result", "1");
			json.put("description", "供应商不存在");
			return buildReqJsonObject(json);
		}else{
			product.setProductSellerId(ps.getId());
		}
		
		String[] imageList = bodyInfo.getString("imageList").split(",");
		for(int i=0;i<imageList.length;i++){
			if(i==0){
				product.setImage1(imageList[i]);
			}else if(i==1){
				product.setImage2(imageList[i]);
			}else if(i==2){
				product.setImage3(imageList[i]);
			}else if(i==3){
				product.setImage4(imageList[i]);
			}
		}
		
		Integer updateProduct = productService.insertSelective(product);
		if(updateProduct != 0){
			System.out.println("---创建商品信息成功---"+product.getId());
			
			//商品创建成功之后插入价格记录表
			Map<String,Object> map=new HashMap<String,Object>();
			map.put("productId", product.getId());
			map.put("price", product.getSalesPrice());
			map.put("createTime", new Date());
			productService.insertProductLog(map);
			
			ProductReward pr = productRewardService.selectByProductId(product.getId());
			//一级佣金比例
			/*String rewardListStr = "";
			for(int i=0;i<rewardList.size();i++){
				if(rewardList.get(i) != null){
					rewardListStr += rewardList.get(i).toString()+",";
				}
			}
			//二级佣金比例
			String rewardList2Str = "";
			for(int i=0;i<rewardList2.size();i++){
				if(rewardList2.get(i) != null){
					rewardList2Str += rewardList2.get(i).toString()+",";
				}
			}
			//佣金发放时间
			String rewardTimeStr = "";
			for(int i=0;i<rewardTime.size();i++){
				if(rewardTime.get(i) != null){
					rewardTimeStr += rewardTime.get(i).toString()+",";
				}
			}*/
			
			Integer prResult = 0;
			
			if(pr == null){
				pr = new ProductReward();
				pr.setProductId(product.getId());
				
				if(bodyInfo.get("partnerReward") != null && !"".equals(bodyInfo.get("partnerReward"))){
					pr.setPartnerReward(Float.valueOf(bodyInfo.getString("partnerReward")));
				}
				if(bodyInfo.get("partnerReward2") != null && !"".equals(bodyInfo.get("partnerReward2"))){
					pr.setPartnerReward2(Float.valueOf(bodyInfo.getString("partnerReward2")));
				}
				if(bodyInfo.get("shopReward") != null && !"".equals(bodyInfo.get("shopReward"))){
					pr.setShopReward(Float.valueOf(bodyInfo.getString("shopReward")));
				}
				if(bodyInfo.get("shopReward2") != null && !"".equals(bodyInfo.get("shopReward2"))){
					pr.setShopReward2(Float.valueOf(bodyInfo.getString("shopReward2")));
				}
				if(bodyInfo.get("saleReward") != null && !"".equals(bodyInfo.get("saleReward"))){
					pr.setSaleReward(Float.valueOf(bodyInfo.getString("saleReward")));
				}
				if(bodyInfo.get("nomalReward2") != null && !"".equals(bodyInfo.get("nomalReward2"))){
					pr.setNomalReward2(Float.valueOf(bodyInfo.getString("nomalReward2")));
				}
				if(bodyInfo.get("nomalReward") != null && !"".equals(bodyInfo.get("nomalReward"))){
					pr.setNomalReward(Float.valueOf(bodyInfo.getString("nomalReward")));
				}
				if(bodyInfo.get("backPercent") != null && !"".equals(bodyInfo.get("backPercent"))){
					pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				}
				if(bodyInfo.get("uplevelPrice") != null && !"".equals(bodyInfo.get("uplevelPrice"))){
					pr.setUplevelPrice(Float.valueOf(bodyInfo.getString("uplevelPrice")));
				}
				if(bodyInfo.get("uplevelPercent") != null && !"".equals(bodyInfo.get("uplevelPercent"))){
					pr.setUplevelPercent(Float.valueOf(bodyInfo.getString("uplevelPercent")));
				}
				
				//pr.setPlatformReward(Float.valueOf(bodyInfo.getString("platformReward")));
				//pr.setAccountRewardlist(rewardListStr);
				//pr.setAccountRewardlist2(rewardList2Str);
				//pr.setAccountRewardtime(rewardTimeStr);
				//pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				prResult = productRewardService.insertSelective(pr);
				
			}else{
				pr.setProductId(product.getId());
				
				if(bodyInfo.get("partnerReward") != null && !"".equals(bodyInfo.get("partnerReward"))){
					pr.setPartnerReward(Float.valueOf(bodyInfo.getString("partnerReward")));
				}
				if(bodyInfo.get("partnerReward2") != null && !"".equals(bodyInfo.get("partnerReward2"))){
					pr.setPartnerReward2(Float.valueOf(bodyInfo.getString("partnerReward2")));
				}
				if(bodyInfo.get("shopReward") != null && !"".equals(bodyInfo.get("shopReward"))){
					pr.setShopReward(Float.valueOf(bodyInfo.getString("shopReward")));
				}
				if(bodyInfo.get("shopReward2") != null && !"".equals(bodyInfo.get("shopReward2"))){
					pr.setShopReward2(Float.valueOf(bodyInfo.getString("shopReward2")));
				}
				if(bodyInfo.get("saleReward") != null && !"".equals(bodyInfo.get("saleReward"))){
					pr.setSaleReward(Float.valueOf(bodyInfo.getString("saleReward")));
				}
				if(bodyInfo.get("nomalReward2") != null && !"".equals(bodyInfo.get("nomalReward2"))){
					pr.setNomalReward2(Float.valueOf(bodyInfo.getString("nomalReward2")));
				}
				if(bodyInfo.get("nomalReward") != null && !"".equals(bodyInfo.get("nomalReward"))){
					pr.setNomalReward(Float.valueOf(bodyInfo.getString("nomalReward")));
				}
				if(bodyInfo.get("backPercent") != null && !"".equals(bodyInfo.get("backPercent"))){
					pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				}
				if(bodyInfo.get("uplevelPrice") != null && !"".equals(bodyInfo.get("uplevelPrice"))){
					pr.setUplevelPrice(Float.valueOf(bodyInfo.getString("uplevelPrice")));
				}
				if(bodyInfo.get("uplevelPercent") != null && !"".equals(bodyInfo.get("uplevelPercent"))){
					pr.setUplevelPercent(Float.valueOf(bodyInfo.getString("uplevelPercent")));
				}
				
				//pr.setPlatformReward(Float.valueOf(bodyInfo.getString("platformReward")));
				//pr.setAccountRewardlist(rewardListStr);
				//pr.setAccountRewardlist2(rewardList2Str);
				//pr.setAccountRewardtime(rewardTimeStr);
				//pr.setBackPercent(Float.valueOf(bodyInfo.getString("backPercent")));
				prResult = productRewardService.updateByPrimaryKeySelective(pr);
			}
			if(prResult == 0){
    			System.out.println("---新增商品佣金比例失败---");
    			json.put("result", "1");
    			json.put("description", "新增商品佣金比例失败");
    			return buildReqJsonObject(json);
    		}else{
    			System.out.println("---新增或修改商品销佣金比例成功---");
    		}
			
			//更新库存，限购数量
			ProductCount pc = new ProductCount();
			pc.setLock(0);
			pc.setSell(0);
			pc.setProductId(product.getId());
			pc.setRestriction(999);
			
			if(bodyInfo.get("stock") != null && !"".equals(bodyInfo.get("stock"))){
				pc.setStock(Integer.valueOf(bodyInfo.getString("stock")));
			}else{
				pc.setStock(Integer.valueOf(bodyInfo.getString("stock")));
			}
			if(bodyInfo.get("stockAlgorithm") != null && !"".equals(bodyInfo.get("stockAlgorithm"))){
				pc.setStockAlgorithm((byte)9);
			}else{
				pc.setStock(9999);
			}
			Integer updatePC = productCountService.insertSelective(pc);
			if(updatePC == 0){
				json.put("result", "1");
				json.put("description", "新增商品库存，限购数量出错");
				return buildReqJsonObject(json);
			}
			
			for(int i=0;i<saleAreaList.size();i++){
				if(saleAreaList.get(i) != null){
					Map<String,Object> para = new HashMap<>();
		        	para.put("productId", product.getId());
		        	para.put("mallUuid", saleAreaList.get(i));
		        	Mall mall = mallService.selectByMallUuid(saleAreaList.get(i).toString());
		        	if(mall != null && !"hdnksdftu123bzz".equals(mall.getMallUuid())){
		        		List<ProductMall> pmList = productMallService.selectByPara(para);
		        		ProductMall pm = null;
			        	if(pmList.size()<=0){
			        		pm = new ProductMall();
			        		pm.setMallUuid(mall.getMallUuid());
			        		pm.setProductId(product.getId());
			        		pm.setCreateTime(new Date());
			        		Integer insertPM = productMallService.insertSelective(pm);
			        		if(insertPM == 0){
			        			System.out.println("---新增商品销售范围失败---");
			        			json.put("result", "1");
			        			json.put("description", "新增商品销售范围失败");
			        			return buildReqJsonObject(json);
			        		}else{
			        			System.out.println("---新增商品销售范围成功---");
			        		}
			        	}
		        	}
				}
			}
		}else{
			json.put("result", "1");
			json.put("description", "创建商品信息失败");
			return buildReqJsonObject(json);
		}
		
		json.put("result", "0");
		json.put("description", "创建商品信息成功");
		json.put("productId", product.getId());
		return buildReqJsonObject(json);
	}
	
	
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public String delete() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		Integer rs = productService.deleteByPrimaryKey(product.getId());
		if(rs==1){//删除商品之后删除商品的价格记录信息
			productService.delProPriLogByProductId(product.getId());
		}
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品删除失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品删除成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "inAndOut", method = RequestMethod.POST)
	@ResponseBody
	public String inAndOut() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}else if(bodyInfo.get("type") == null || "".equals(bodyInfo.get("type"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		String message = "";
		
		if("0".equals(bodyInfo.getString("type"))){
			product.setIsUndertake((byte)0);
			message = "下架";
		}else if("1".equals(bodyInfo.getString("type"))){
			product.setIsUndertake((byte)1);
			message = "上传";
		}
		Integer rs = productService.updateByPrimaryKeySelective(product);
		
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品"+message+"失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品"+message+"成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "listOfMall", method = RequestMethod.POST)
	@ResponseBody
	public String listOfMall() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		List<Product> productList = new ArrayList<>(),productListAll = new ArrayList<>();
		
		Map<String,Object> para = new HashMap<>();
		if (bodyInfo.get("productId") != null && !"".equals(bodyInfo.get("productId"))) {
			para.put("productId", bodyInfo.getString("productId"));
		}
		
		int type = 0;
		
		if (bodyInfo.get("mallUuid") != null && !"".equals(bodyInfo.get("mallUuid"))) {
			Mall mall = mallService.selectByMallUuid(bodyInfo.getString("mallUuid")); 
			if(mall != null && !"商盟惠购".equals(mall.getMallName())){
				para.put("mallUuid", bodyInfo.getString("mallUuid"));
				type = 1;
			}
		}
		
		int count = 0;
		
		if(type == 1){
			List<ProductMall> pmAllList = productMallService.selectByPara(para);
			count = pmAllList.size();
		}else{
			productListAll = productService.selectByPara(para);
			count = productListAll.size();
		}
		
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			para.put("start", (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
			para.put("size", Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		if(type == 1){
			List<ProductMall> pmAllList = productMallService.selectByPara(para);
			for(ProductMall pm:pmAllList){
				Product product = productService.selectByPrimaryKey(pm.getProductId());
				productList.add(product);
			}
		}else{
			productList = productService.selectByPara(para);
		}
		
		if(productList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商品列表不存在");
			return buildReqJsonObject(json);
		}
		List<Map<String,String>> list = new ArrayList<>();
		for(Product product:productList){
			Map<String,String> map = new HashMap<>();
			Mall orderMall = mallService.selectByMallUuid(product.getMallUuid());
			
			map.put("id", product.getId()+"");
			map.put("image1", product.getImage1()+"");
			if(orderMall == null){
				map.put("mallName", "商盟惠购商城");
			}else{
				map.put("mallName", orderMall.getMallName()+"商城");
			}
			if(product.getType() == 0){
				map.put("type", "普通商品");
			}else{
				map.put("type", "可套餐商品");
			}
			map.put("name", product.getName()+"");
			map.put("salesPrice", product.getSalesPrice()+"");
			map.put("createTime", product.getCreateTime()==null?"":sdf.format(product.getCreateTime()));
			list.add(map);
		}
		
    	json.put("result", "0");
		json.put("description", "获取商品列表成功");
		json.put("list", list);
		json.put("count", count);
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "deleteMallProduct", method = RequestMethod.POST)
	@ResponseBody
	public String deleteMallProduct() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}else if(bodyInfo.get("mallUuid") == null || "".equals(bodyInfo.get("mallUuid"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Map<String,Object> para = new HashMap<>();
		para.put("productId", Integer.valueOf(bodyInfo.getString("productId")));
		para.put("mallUuid", bodyInfo.getString("mallUuid"));
		List<ProductMall> pm = productMallService.selectByPara(para);
		if(pm.size() < 1){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		Integer rs = productMallService.deleteByPrimaryKey(pm.get(0).getId());
		
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品下架失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品下架成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "listOfCategory", method = RequestMethod.POST)
	@ResponseBody
	public String listOfCategory() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		net.sf.json.JSONArray categoryList = bodyInfo.getJSONArray("categoryList");
		
		int right = 1;
		if(categoryList.size() == 0 || categoryList == null) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		List<Product> producAllList = new ArrayList<>();
		Map<String,Object> para = new HashMap<>();
		for(int i=0;i<categoryList.size();i++){
			if(categoryList.get(i) != null){
				para.put("categoryId", categoryList.get(i).toString());
				List<Product> productList = productService.selectByPara(para);
				if(categoryList.size()>0){
					producAllList.addAll(productList);
				}
			}
		}
		
		if(producAllList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商品列表不存在");
			return buildReqJsonObject(json);
		}
		List<Map<String,String>> list = new ArrayList<>();
		for(Product product:producAllList){
			Map<String,String> map = new HashMap<>();
			
			map.put("id", product.getId()+"");
			map.put("name", product.getName()+"");
			list.add(map);
		}
		
    	json.put("result", "0");
		json.put("description", "获取商品列表成功");
		json.put("list", list);
		return buildReqJsonObject(json);
	}
	
	
	
	@RequestMapping(value = "productLogList", method = RequestMethod.POST)
	@ResponseBody
	public String productLogList() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		Map<String,Object> para = new HashMap<>();
		if (bodyInfo.get("productId") != null && !"".equals(bodyInfo.get("productId"))) {
			para.put("productId", bodyInfo.getString("productId"));
		}
		if(bodyInfo.get("name") != null && !"".equals(bodyInfo.get("name"))) {
			para.put("name", bodyInfo.getString("name"));
		}
		
		List<Map<String, Object>> productPriceLogListAll=productService.selectProLogByPara(para);

		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			para.put("start", (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
			para.put("size", Integer.valueOf(bodyInfo.getString("pageSize")));
		}

		List<Map<String, Object>> productPriceLogList=productService.selectProLogByPara(para);

		if(productPriceLogList.size() <= 0){
			json.put("result", "1");
			json.put("description", "没有商品价格走势信息！");
			return buildReqJsonObject(json);
		}
		for(Map<String,Object> maps:productPriceLogList){
			Product prod=productService.selectByPrimaryKey(Integer.valueOf(maps.get("productId")+""));
			maps.put("createTime",maps.get("createTime")+"");
			maps.put("name", prod.getName());
		}
		
    	json.put("result", "0");
		json.put("description", "获取商品价格列表成功");
		json.put("list", productPriceLogList);
		json.put("count", productPriceLogListAll.size());
		return buildReqJsonObject(json);
	}
	
	
	
	@RequestMapping(value = "saveProductPrice", method = RequestMethod.POST)
	@ResponseBody
	public String saveProductPrice() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		int trues=0;
		if (bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			trues=1;
		}if(bodyInfo.get("productPrice") == null || "".equals(bodyInfo.get("productPrice"))) {
			trues=1;
		}if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			trues=1;
		}
		if(trues==1){
			json.put("result", "1");
			json.put("description", "请检查参数输入是否正确");
			return buildReqJsonObject(json);
		}
		int res=0;
		if(bodyInfo.getInt("id")==0){
			Map<String,Object> map=new HashMap<String,Object>();
			map.put("productId",bodyInfo.getInt("productId"));
			map.put("price",Float.valueOf(bodyInfo.getString("productPrice")));
			map.put("createTime", new Date());
			res=productService.insertProductLog(map);
		}else{
			Map<String,Object> map=new HashMap<String,Object>();
			map.put("id",bodyInfo.getInt("id"));
			map.put("price",Float.valueOf(bodyInfo.getString("productPrice")));
			res=productService.updateProPriLog(map);
		}

		if(res==1){
			json.put("result", "0");
			json.put("description", "操作成功！");
		}else{
			json.put("result", "1");
			json.put("description", "操作失败！");
		}
		return buildReqJsonObject(json);
	}
	
	
	
	@RequestMapping(value = "selProPriLogById", method = RequestMethod.POST)
	@ResponseBody
	public String selProPriLogById() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		int trues=0;
		if (bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			trues=1;
		}
		if(trues==1){
			json.put("result", "1");
			json.put("description", "请检查参数输入是否正确");
			return buildReqJsonObject(json);
		}
		Map<String,Object> map=productService.selectProLogById(bodyInfo.getInt("id"));

		if(map!=null){
			json.put("result", "0");
			json.put("description", "查询成功！");
			json.put("map", map);
		}else{
			json.put("result", "1");
			json.put("description", "未查询到相关信息！");
		}
		return buildReqJsonObject(json);
	}
	
	
	@RequestMapping(value = "deleteProPriLog", method = RequestMethod.POST)
	@ResponseBody
	public String deleteProPriLog() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		int trues=0;
		if (bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			trues=1;
		}
		if(trues==1){
			json.put("result", "1");
			json.put("description", "请检查参数输入是否正确");
			return buildReqJsonObject(json);
		}
		int res=productService.delProPriLog(bodyInfo.getInt("id"));

		if(res==1){
			json.put("result", "0");
			json.put("description", "删除成功！");
		}else{
			json.put("result", "1");
			json.put("description", "删除失败");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "listOfFormat", method = RequestMethod.POST)
	@ResponseBody
	public String listOfFormat() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		Map<String,Object> para = new HashMap<>();
		para.put("productId", product.getId());
		List<ProductColor> pcList = productColorService.selectByPara(para);
		List<ProductProcessingMethods> ppmList = productProcessingMethodsService.selectByPara(para);
		List<ProductStyle> pstyleList = productStyleService.selectByPara(para);
		List<ProductSize> psizeList = productSizeService.selectByPara(para);
		
		int count = pcList.size()+ppmList.size()+pstyleList.size()+psizeList.size();
		
		if(count==0){
			json.put("result", "1");
			json.put("description", "暂无规格");
			return buildReqJsonObject(json);
		}
		
		//1.尺寸，2.颜色，3.款式，4.加工方式
		List<Map<String,String>> list = new ArrayList<>();
		if(psizeList.size()>0){
			for(ProductSize psize:psizeList){
				Map<String,String> map = new HashMap<>();
				map.put("id", psize.getId()+"");
				map.put("productId", psize.getProductId()+"");
				map.put("name", psize.getNameOfSize()+"");
				map.put("basePrice", psize.getBasePrice()+"");
				map.put("isActive", psize.getIsActive()+"");
				switch(psize.getIsActive()){
				case 0:
					map.put("isActiveValue", "未激活");
					break;
				case 1:
					map.put("isActiveValue", "已激活");
					break;
				}
				map.put("type", "1");
				map.put("typeValue", "尺寸");
				map.put("createTime", psize.getCreateTime()==null?"":sdf.format(psize.getCreateTime()));
				list.add(map);
			}
		}
		if(pcList.size()>0){
			for(ProductColor pc:pcList){
				Map<String,String> map = new HashMap<>();
				map.put("id", pc.getId()+"");
				map.put("productId", pc.getProductId()+"");
				map.put("name", pc.getNameOfColor()+"");
				map.put("basePrice", pc.getBasePrice()+"");
				map.put("isActive", pc.getIsActive()+"");
				switch(pc.getIsActive()){
				case 0:
					map.put("isActiveValue", "未激活");
					break;
				case 1:
					map.put("isActiveValue", "已激活");
					break;
				}
				map.put("type", "2");
				map.put("typeValue", "颜色");
				map.put("createTime", pc.getCreateTime()==null?"":sdf.format(pc.getCreateTime()));
				list.add(map);
			}
		}
		if(pstyleList.size()>0){
			for(ProductStyle pstyle:pstyleList){
				Map<String,String> map = new HashMap<>();
				map.put("id", pstyle.getId()+"");
				map.put("productId", pstyle.getProductId()+"");
				map.put("name", pstyle.getNameOfStyle()+"");
				map.put("basePrice", pstyle.getBasePrice()+"");
				map.put("isActive", pstyle.getIsActive()+"");
				switch(pstyle.getIsActive()){
				case 0:
					map.put("isActiveValue", "未激活");
					break;
				case 1:
					map.put("isActiveValue", "已激活");
					break;
				}
				map.put("type", "3");
				map.put("typeValue", "款式");
				map.put("createTime", pstyle.getCreateTime()==null?"":sdf.format(pstyle.getCreateTime()));
				list.add(map);
			}
		}
		if(ppmList.size()>0){
			for(ProductProcessingMethods ppm:ppmList){
				Map<String,String> map = new HashMap<>();
				map.put("id", ppm.getId()+"");
				map.put("productId", ppm.getProductId()+"");
				map.put("name", ppm.getNameOfProcessingMethods()+"");
				map.put("basePrice", ppm.getBasePrice()+"");
				map.put("isActive", ppm.getIsActive()+"");
				switch(ppm.getIsActive()){
				case 0:
					map.put("isActiveValue", "未激活");
					break;
				case 1:
					map.put("isActiveValue", "已激活");
					break;
				}
				map.put("type", "4");
				map.put("typeValue", "加工方式");
				map.put("createTime", ppm.getCreateTime()==null?"":sdf.format(ppm.getCreateTime()));
				list.add(map);
			}
		}
		
		int start = 0,size = list.size();
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
				start = (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize"));
				size = Integer.valueOf(bodyInfo.getString("page"))*Integer.valueOf(bodyInfo.getString("pageSize"));
			}
		}
		
		System.out.println("---start---"+start);
		System.out.println("---size---"+size);
		
		if(list.size()<=size){
			size = list.size();
		}
		List<Map<String,String>> viewList = new ArrayList<>();
		for(int i=start;i<size;i++){
			viewList.add(list.get(i));
		}
		json.put("result", "0");
		json.put("description", "获取商品规格列表成功");
		json.put("list", viewList);
		json.put("count", count);
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "createFormat", method = RequestMethod.POST)
	@ResponseBody
	public String createFormat() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}else if(bodyInfo.get("name") == null || "".equals(bodyInfo.get("name"))) {
			right = 0;
		}else if(bodyInfo.get("type") == null || "".equals(bodyInfo.get("type"))) {
			right = 0;
		}else if(bodyInfo.get("isActive") == null || "".equals(bodyInfo.get("isActive"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		Integer rs = 0;
		String[] nameArr = (bodyInfo.get("name")+"").split(" ");
		//1.尺寸，2.颜色，3.款式，4.加工方式
		switch(Integer.valueOf(bodyInfo.get("type")+"")){
		case 1:
			ProductSize productSize = new ProductSize();
			productSize.setProductId(Integer.valueOf(bodyInfo.get("productId")+""));
			productSize.setIsActive(Byte.valueOf(bodyInfo.get("isActive")+""));
			productSize.setCreateTime(new Date());
			//productSize.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			for(String name :nameArr){
				productSize.setNameOfSize(name);
				rs = productSizeService.insertSelective(productSize);
				if(rs != 1){
					json.put("result", "1");
					json.put("description", "商品规格添加失败");
					return buildReqJsonObject(json);
				}
			}
			break;
		case 2:
			ProductColor productColor = new ProductColor();
			productColor.setProductId(Integer.valueOf(bodyInfo.get("productId")+""));
			productColor.setIsActive(Byte.valueOf(bodyInfo.get("isActive")+""));
			productColor.setCreateTime(new Date());
			//productColor.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			for(String name :nameArr){
				productColor.setNameOfColor(name);
				rs = productColorService.insertSelective(productColor);
				if(rs != 1){
					json.put("result", "1");
					json.put("description", "商品规格添加失败");
					return buildReqJsonObject(json);
				}
			}
			break;
		case 3:
			ProductStyle productStyle = new ProductStyle();
			productStyle.setProductId(Integer.valueOf(bodyInfo.get("productId")+""));
			productStyle.setIsActive(Byte.valueOf(bodyInfo.get("isActive")+""));
			productStyle.setCreateTime(new Date());
			//productStyle.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			for(String name :nameArr){
				productStyle.setNameOfStyle(name);
				rs = productStyleService.insertSelective(productStyle);
				if(rs != 1){
					json.put("result", "1");
					json.put("description", "商品规格添加失败");
					return buildReqJsonObject(json);
				}
			}
			break;
		case 4:
			ProductProcessingMethods productProcessingMethods = new ProductProcessingMethods();
			productProcessingMethods.setProductId(Integer.valueOf(bodyInfo.get("productId")+""));
			productProcessingMethods.setIsActive(Byte.valueOf(bodyInfo.get("isActive")+""));
			productProcessingMethods.setCreateTime(new Date());
			//productProcessingMethods.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			for(String name :nameArr){
				productProcessingMethods.setNameOfProcessingMethods(name);
				rs = productProcessingMethodsService.insertSelective(productProcessingMethods);
				if(rs != 1){
					json.put("result", "1");
					json.put("description", "商品规格添加失败");
					return buildReqJsonObject(json);
				}
			}
			break;
		}
		
		json.put("result", "0");
		json.put("description", "商品规格添加成功");
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "modifyFormatPrice", method = RequestMethod.POST)
	@ResponseBody
	public String modifyFormatPrice() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			right = 0;
		}else if(bodyInfo.get("type") == null || "".equals(bodyInfo.get("type"))) {
			right = 0;
		}else if(bodyInfo.get("basePrice") == null || "".equals(bodyInfo.get("basePrice"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Integer rs = 0;
		
		//1.尺寸，2.颜色，3.款式，4.加工方式
		switch(Integer.valueOf(bodyInfo.get("type")+"")){
		case 1:
			ProductSize productSize = productSizeService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productSize == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productSize.setBasePrice(Float.valueOf(bodyInfo.getString("basePrice")+""));
			rs = productSizeService.updateByPrimaryKeySelective(productSize);
			break;
		case 2:
			ProductColor productColor = productColorService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productColor == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productColor.setBasePrice(Float.valueOf(bodyInfo.getString("basePrice")+""));
			rs = productColorService.updateByPrimaryKeySelective(productColor);
			break;
		case 3:
			ProductStyle productStyle = productStyleService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productStyle == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productStyle.setBasePrice(Float.valueOf(bodyInfo.getString("basePrice")+""));
			rs = productStyleService.updateByPrimaryKeySelective(productStyle);
			break;
		case 4:
			ProductProcessingMethods productProcessingMethods = productProcessingMethodsService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productProcessingMethods == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productProcessingMethods.setBasePrice(Float.valueOf(bodyInfo.getString("basePrice")+""));
			rs = productProcessingMethodsService.updateByPrimaryKeySelective(productProcessingMethods);
			break;
		}
		
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品规格删除失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品规格删除成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "modifyFormatPriceNew", method = RequestMethod.POST)
	@ResponseBody
	public String modifyFormatPriceNew() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}else if(bodyInfo.get("productSizeId") == null || "".equals(bodyInfo.get("productSizeId"))) {
			right = 0;
		}else if(bodyInfo.get("productColorId") == null || "".equals(bodyInfo.get("productColorId"))) {
			right = 0;
		}else if(bodyInfo.get("productStyleId") == null || "".equals(bodyInfo.get("productStyleId"))) {
			right = 0;
		}else if(bodyInfo.get("productProcessingMethodsId") == null || "".equals(bodyInfo.get("productProcessingMethodsId"))) {
			right = 0;
		}else if(bodyInfo.get("basePrice") == null || "".equals(bodyInfo.get("basePrice"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Map<String,Object> para = new HashMap<>();
		para.put("productId", Integer.valueOf(bodyInfo.getString("productId")));
		para.put("productSizeId", Integer.valueOf(bodyInfo.getString("productSizeId")));
		para.put("productColorId", Integer.valueOf(bodyInfo.getString("productColorId")));
		para.put("productStyleId", Integer.valueOf(bodyInfo.getString("productStyleId")));
		para.put("productProcessingMethodsId", Integer.valueOf(bodyInfo.getString("productProcessingMethodsId")));
		List<ProductFormatPrice> pfpList = productFormatPriceService.selectByPara(para);
		
		ProductFormatPrice pfp = null;
		Integer rs = 0;
		if(pfpList.size()<=0){
			pfp = new ProductFormatPrice();
			pfp.setProductId(Integer.valueOf(bodyInfo.getString("productId")));
			pfp.setProductSizeId(Integer.valueOf(bodyInfo.getString("productSizeId")));
			pfp.setProductColorId(Integer.valueOf(bodyInfo.getString("productColorId")));
			pfp.setProductStyleId(Integer.valueOf(bodyInfo.getString("productStyleId")));
			pfp.setProductProcessingMethodsId(Integer.valueOf(bodyInfo.getString("productProcessingMethodsId")));
			pfp.setIsActive((byte)1);
			pfp.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			pfp.setCreateTime(new Date());
			
			rs = productFormatPriceService.insertSelective(pfp);
		}else{
			pfp = pfpList.get(0);
			pfp.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			
			rs = productFormatPriceService.updateByPrimaryKeySelective(pfp);
		}
		
		
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品规格组合价格修改失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品规格组合价格修改成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "modifyFormat", method = RequestMethod.POST)
	@ResponseBody
	public String modifyFormat() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			right = 0;
		}else if(bodyInfo.get("type") == null || "".equals(bodyInfo.get("type"))) {
			right = 0;
		}else if(bodyInfo.get("name") == null || "".equals(bodyInfo.get("name"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Integer rs = 0;
		
		//1.尺寸，2.颜色，3.款式，4.加工方式
		switch(Integer.valueOf(bodyInfo.get("type")+"")){
		case 1:
			ProductSize productSize = productSizeService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productSize == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productSize.setNameOfSize(bodyInfo.getString("name"));
			rs = productSizeService.updateByPrimaryKeySelective(productSize);
			break;
		case 2:
			ProductColor productColor = productColorService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productColor == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productColor.setNameOfColor(bodyInfo.getString("name"));
			rs = productColorService.updateByPrimaryKeySelective(productColor);
			break;
		case 3:
			ProductStyle productStyle = productStyleService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productStyle == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productStyle.setNameOfStyle(bodyInfo.getString("name"));
			rs = productStyleService.updateByPrimaryKeySelective(productStyle);
			break;
		case 4:
			ProductProcessingMethods productProcessingMethods = productProcessingMethodsService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productProcessingMethods == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			productProcessingMethods.setNameOfProcessingMethods(bodyInfo.getString("name"));
			rs = productProcessingMethodsService.updateByPrimaryKeySelective(productProcessingMethods);
			break;
		}
		
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "规格名称修改失败");
		}else{
			json.put("result", "0");
			json.put("description", "规格名称修改成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "deleteFormat", method = RequestMethod.POST)
	@ResponseBody
	public String deleteFormat() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			right = 0;
		}else if(bodyInfo.get("type") == null || "".equals(bodyInfo.get("type"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		Integer rs = 0;
		
		//1.尺寸，2.颜色，3.款式，4.加工方式
		switch(Integer.valueOf(bodyInfo.get("type")+"")){
		case 1:
			ProductSize productSize = productSizeService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productSize == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			rs = productSizeService.deleteByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			productFormatPriceService.deleteByProductSizeId(Integer.valueOf(bodyInfo.get("id")+""));
			break;
		case 2:
			ProductColor productColor = productColorService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productColor == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			rs = productColorService.deleteByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			productFormatPriceService.deleteByProductColorId(Integer.valueOf(bodyInfo.get("id")+""));
			break;
		case 3:
			ProductStyle productStyle = productStyleService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productStyle == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			rs = productStyleService.deleteByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			productFormatPriceService.deleteByProductStyleId(Integer.valueOf(bodyInfo.get("id")+""));
			break;
		case 4:
			ProductProcessingMethods productProcessingMethods = productProcessingMethodsService.selectByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			if(productProcessingMethods == null){
				json.put("result", "1");
				json.put("description", "规格不存在");
				return buildReqJsonObject(json);
			}
			rs = productProcessingMethodsService.deleteByPrimaryKey(Integer.valueOf(bodyInfo.get("id")+""));
			productFormatPriceService.deleteByProductProcessingMethodsId(Integer.valueOf(bodyInfo.get("id")+""));
			break;
		}
		
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品规格价格保存失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品规格价格保存成功");
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "listOfFormatPrice", method = RequestMethod.POST)
	@ResponseBody
	public String listOfFormatPrice() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		Map<String,Object> para = new HashMap<>();
		para.put("productId", product.getId());
		List<ProductFormatPrice> pfpAllList = productFormatPriceService.selectByPara(para);
		
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			para.put("start", (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
			para.put("size", Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		List<ProductFormatPrice> pfpList = productFormatPriceService.selectByPara(para);
		if(pfpList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商品规格组合价格列表不存在");
			return buildReqJsonObject(json);
		}
		//1.尺寸，2.颜色，3.款式，4.加工方式
		List<Map<String,String>> list = new ArrayList<>();
		for(ProductFormatPrice pfp:pfpList){
			System.out.println(pfp.getProductSizeId()+","+pfp.getProductColorId()+","+pfp.getProductStyleId()+","+pfp.getProductProcessingMethodsId());
			Map<String,String> map = new HashMap<>();
			ProductSize psize = productSizeService.selectByPrimaryKey(pfp.getProductSizeId());
			ProductColor pcolor = productColorService.selectByPrimaryKey(pfp.getProductColorId());
			ProductStyle pstyle = productStyleService.selectByPrimaryKey(pfp.getProductStyleId());
			ProductProcessingMethods ppm = productProcessingMethodsService.selectByPrimaryKey(pfp.getProductProcessingMethodsId());
			
			map.put("id", pfp.getId()+"");
			map.put("productId", pfp.getProductId()+"");
			map.put("sizeName", psize==null?"":psize.getNameOfSize()+"");
			map.put("colorName", pcolor==null?"":pcolor.getNameOfColor()+"");
			map.put("styleName", pstyle==null?"":pstyle.getNameOfStyle()+"");
			map.put("ppmName", ppm==null?"":ppm.getNameOfProcessingMethods()+"");
			map.put("basePrice", pfp.getBasePrice()+"");
			map.put("isActive", pfp.getIsActive()+"");
			switch(psize.getIsActive()){
			case 0:
				map.put("isActiveValue", "未激活");
				break;
			case 1:
				map.put("isActiveValue", "已激活");
				break;
			}
			map.put("createTime", pfp.getCreateTime()==null?"":sdf.format(pfp.getCreateTime()));
			list.add(map);
		}
		
		json.put("result", "0");
		json.put("description", "获取商品规格组合价格列表成功");
		json.put("list", list);
		json.put("count", pfpAllList.size());
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "listOfFormatPriceAll", method = RequestMethod.POST)
	@ResponseBody
	public String listOfFormatPriceAll() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		Map<String,Object> para = new HashMap<>();
		para.put("productId", product.getId());
		
		List<ProductSize> psizeList = productSizeService.selectByPara(para);
		List<ProductColor> pcolorList = productColorService.selectByPara(para);
		List<ProductStyle> pstyleList = productStyleService.selectByPara(para);
		List<ProductProcessingMethods> ppmList = productProcessingMethodsService.selectByPara(para);
		
		if(psizeList.size() <= 0 || pcolorList.size() <= 0 || pstyleList.size() <= 0 || ppmList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商品规格组列表不存在");
			return buildReqJsonObject(json);
		}
		
		//1.尺寸，2.颜色，3.款式，4.加工方式
		List<Map<String,String>> list = new ArrayList<>();
		for(ProductSize psize:psizeList){
			for(ProductColor pcolor:pcolorList){
				for(ProductStyle pstyle:pstyleList){
					for(ProductProcessingMethods ppm:ppmList){
						
						Map<String,String> map = new HashMap<>();
						para.put("productSizeId", psize.getId());
						para.put("productColorId", pcolor.getId());
						para.put("productStyleId", pstyle.getId());
						para.put("productProcessingMethodsId", ppm.getId());
						List<ProductFormatPrice> pfpList = productFormatPriceService.selectByPara(para);
						if(pfpList.size()>0){
							map.put("id", pfpList.get(0).getId()+"");
							map.put("basePrice", pfpList.get(0).getBasePrice()+"");
							map.put("isActive", pfpList.get(0).getIsActive()+"");
							switch(pfpList.get(0).getIsActive()){
							case 0:
								map.put("isActiveValue", "未激活");
								break;
							case 1:
								map.put("isActiveValue", "已激活");
								break;
							}
							map.put("createTime", pfpList.get(0).getCreateTime()==null?"":sdf.format(pfpList.get(0).getCreateTime()));
						}else{
							map.put("id", "无");
							map.put("basePrice", "0");
							map.put("isActive", "0");
							map.put("isActiveValue", "未激活");
							map.put("createTime", psize.getCreateTime()==null?"":sdf.format(psize.getCreateTime()));
						}
						
						map.put("productId", psize.getProductId()+"");
						map.put("sizeName", psize==null?"":psize.getNameOfSize()+"");
						map.put("colorName", pcolor==null?"":pcolor.getNameOfColor()+"");
						map.put("styleName", pstyle==null?"":pstyle.getNameOfStyle()+"");
						map.put("ppmName", ppm==null?"":ppm.getNameOfProcessingMethods()+"");
						
						map.put("productSizeId", psize.getId()+"");
						map.put("productColorId", pcolor.getId()+"");
						map.put("productStyleId", pstyle.getId()+"");
						map.put("productProcessingMethodsId", ppm.getId()+"");
						
						list.add(map);
					}
				}
			}
		}
		
		int start = 0,size = list.size();
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
				start = (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize"));
				size = Integer.valueOf(bodyInfo.getString("page"))*Integer.valueOf(bodyInfo.getString("pageSize"));
			}
		}
		
		System.out.println("---start---"+start);
		System.out.println("---size---"+size);
		
		if(list.size()<=size){
			size = list.size();
		}
		List<Map<String,String>> viewList = new ArrayList<>();
		for(int i=start;i<size;i++){
			viewList.add(list.get(i));
		}
		
		json.put("result", "0");
		json.put("description", "获取商品规格组合价格列表成功");
		json.put("list", viewList);
		json.put("count", list.size());
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "createOfFormatPrice", method = RequestMethod.POST)
	@ResponseBody
	public String createOfFormatPrice() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("productId") == null || "".equals(bodyInfo.get("productId"))) {
			right = 0;
		}else if(bodyInfo.get("productSizeId") == null || "".equals(bodyInfo.get("productSizeId"))) {
			right = 0;
		}else if(bodyInfo.get("productColorId") == null || "".equals(bodyInfo.get("productColorId"))) {
			right = 0;
		}else if(bodyInfo.get("productStyleId") == null || "".equals(bodyInfo.get("productStyleId"))) {
			right = 0;
		}else if(bodyInfo.get("productProcessingMethodsId") == null || "".equals(bodyInfo.get("productProcessingMethodsId"))) {
			right = 0;
		}else if(bodyInfo.get("basePrice") == null || "".equals(bodyInfo.get("basePrice"))) {
			right = 0;
		}else if(bodyInfo.get("isActive") == null || "".equals(bodyInfo.get("isActive"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		Product product = productService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productId")));
		if(product == null){
			json.put("result", "1");
			json.put("description", "商品不存在");
			return buildReqJsonObject(json);
		}
		
		ProductSize psize = productSizeService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productSizeId")));
		ProductColor pcolor = productColorService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productColorId")));
		ProductStyle pstyle = productStyleService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productStyleId")));
		ProductProcessingMethods ppm = productProcessingMethodsService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("productProcessingMethodsId")));
		if(psize == null){
			json.put("result", "1");
			json.put("description", "该尺寸不存在");
			return buildReqJsonObject(json);
		}
		if(pcolor == null){
			json.put("result", "1");
			json.put("description", "该颜色不存在");
			return buildReqJsonObject(json);
		}
		if(pstyle == null){
			json.put("result", "1");
			json.put("description", "该款式不存在");
			return buildReqJsonObject(json);
		}
		if(ppm == null){
			json.put("result", "1");
			json.put("description", "该加工方式不存在");
			return buildReqJsonObject(json);
		}
		//1.尺寸，2.颜色，3.款式，4.加工方式
		
		Map<String,Object> para = new HashMap<>();
		para.put("productId", Integer.valueOf(bodyInfo.getString("productId")));
		para.put("productSizeId", Integer.valueOf(bodyInfo.getString("productSizeId")));
		para.put("productColorId", Integer.valueOf(bodyInfo.getString("productColorId")));
		para.put("productStyleId", Integer.valueOf(bodyInfo.getString("productStyleId")));
		para.put("productProcessingMethodsId", Integer.valueOf(bodyInfo.getString("productProcessingMethodsId")));
		ProductFormatPrice pfp = productFormatPriceService.selectByAllId(para);
		if(pfp != null){
			json.put("result", "1");
			json.put("description", "该商品规格组合已存在");
			return buildReqJsonObject(json);
		}else{
			pfp = new ProductFormatPrice();
			pfp.setProductId(Integer.valueOf(bodyInfo.get("productId")+""));
			pfp.setProductSizeId(Integer.valueOf(bodyInfo.get("productSizeId")+""));
			pfp.setProductColorId(Integer.valueOf(bodyInfo.get("productColorId")+""));
			pfp.setProductStyleId(Integer.valueOf(bodyInfo.get("productStyleId")+""));
			pfp.setProductProcessingMethodsId(Integer.valueOf(bodyInfo.get("productProcessingMethodsId")+""));
			pfp.setBasePrice(Float.valueOf(bodyInfo.get("basePrice")+""));
			pfp.setIsActive(Byte.valueOf(bodyInfo.get("isActive")+""));
			pfp.setCreateTime(new Date());
			
			Integer rs = productFormatPriceService.insertSelective(pfp);
			if(rs != 1){
				json.put("result", "1");
				json.put("description", "创建商品规格组合失败");
			}else{
				json.put("result", "0");
				json.put("description", "创建商品规格组合成功");
			}
		}
		return buildReqJsonObject(json);
	}
	
	@RequestMapping(value = "deleteFormatPrice", method = RequestMethod.POST)
	@ResponseBody
	public String deleteFormatPrice() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		int right = 1;
		if(bodyInfo.get("id") == null || "".equals(bodyInfo.get("id"))) {
			right = 0;
		}
		if(right == 0){
			json.put("result", "1");
			json.put("description", "操作失败，请检查输入的参数是否完整");
			return buildReqJsonObject(json);
		}
		
		ProductFormatPrice pfp = productFormatPriceService.selectByPrimaryKey(Integer.valueOf(bodyInfo.getString("id")));
		
		if(pfp == null){
			json.put("result", "1");
			json.put("description", "商品规格组合不存在");
			return buildReqJsonObject(json);
		}
		Integer rs = productFormatPriceService.deleteByPrimaryKey(pfp.getId());
		if(rs != 1){
			json.put("result", "1");
			json.put("description", "商品规格组合删除失败");
		}else{
			json.put("result", "0");
			json.put("description", "商品规格组合删除成功");
		}
		return buildReqJsonObject(json);
	}
	
	
	/**
	 * 查询各个品牌商品列表
	 * @return
	 */
	@RequestMapping(value = "listOfSeller", method = RequestMethod.POST)
	@ResponseBody
	public String listOfSeller() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		List<Product> productList = new ArrayList<>(),productListAll = new ArrayList<>();
		Map<String,Object> para = new HashMap<>();
		
		if(manager.getType() == 3){
			para.put("productSellerId", manager.getProductSellerId());
		}
		
		if (bodyInfo.get("productId") != null && !"".equals(bodyInfo.get("productId"))) {
			para.put("productId", bodyInfo.getString("productId"));
		}
		
		productListAll = productService.selectByPara(para);
		
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			para.put("start", (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
			para.put("size", Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		
		productList = productService.selectByPara(para);
		if(productList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商品列表不存在");
			return buildReqJsonObject(json);
		}
		List<Map<String,String>> list = new ArrayList<>();
		for(Product product:productList){
			Map<String,String> map = new HashMap<>();
			Mall orderMall = mallService.selectByMallUuid(product.getMallUuid());
			
			map.put("id", product.getId()+"");
			map.put("orderNumber", product.getOrderNumber()+"");
			map.put("image1", product.getImage1()+"");
			if(orderMall == null){
				map.put("mallName", "商盟惠购商城");
			}else{
				map.put("mallName", orderMall.getMallName()+"商城");
			}
			
			
			if(product.getpType() == 1){
				map.put("type", "普通商品");
			}else if(product.getpType() == 4){
				map.put("type", "个人商品");
			}else{
				map.put("type", "套餐商品");
			}
			map.put("name", product.getName()+"");
			
			Category category = categoryService.selectByPrimaryKey(product.getCategoryId());
			if(category == null){
				map.put("categoryName", "");
			}else{
				map.put("categoryName", category.getName()+"");
			}
			ProductSeller ps = productSellerService.selectByPrimaryKey(product.getProductSellerId());
			if(ps == null){
				map.put("productSellerName", "");
			}else{
				map.put("productSellerName", ps.getName()+"");
			}
			map.put("salesPrice", product.getSalesPrice()+"");
			map.put("marketPrice", product.getMarketPrice()==null?"0":product.getMarketPrice()+"");
			map.put("createTime", product.getCreateTime()==null?"":sdf.format(product.getCreateTime()));
			list.add(map);
		}
		
    	json.put("result", "0");
		json.put("description", "获取商品列表成功");
		json.put("list", list);
		json.put("count", productListAll.size());
		return buildReqJsonObject(json);
	}
	
	/**
	 * 微店个人商品申请操作
	 * @return
	 */
	@RequestMapping(value = "listApplyAccountProduct", method = RequestMethod.POST)
	@ResponseBody
	public String listApplyAccountProduct() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
		
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		
		
		Map<String,Object> para = new HashMap<>();
		if (bodyInfo.get("accountId") != null && !"".equals(bodyInfo.get("accountId"))) {
			para.put("accountId", bodyInfo.getString("accountId"));
		}
		if (bodyInfo.get("status") != null && !"".equals(bodyInfo.get("status"))) {
			int status=Integer.parseInt(bodyInfo.getString("status")+"");
			if(status!=4){
				para.put("status", bodyInfo.getString("status"));
			}
		}
		List<Map<String,Object>> dListAll =productService.selectToApply(para);
		
		if(bodyInfo.get("page") != null && !"".equals(bodyInfo.get("page"))) {
			para.put("start", (Integer.valueOf(bodyInfo.getString("page"))-1)*Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		if(bodyInfo.get("pageSize") != null && !"".equals(bodyInfo.get("pageSize"))) {
			para.put("size", Integer.valueOf(bodyInfo.getString("pageSize")));
		}
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<Map<String,Object>> dList =productService.selectToApply(para);
		
		if(dList.size() <= 0){
			json.put("result", "1");
			json.put("description", "商家列表不存在");
			return buildReqJsonObject(json);
		}
		List<Map<String,Object>> list = new ArrayList<>();
		for(Map<String,Object> d:dList){
			
			Map<String,Object> map = new HashMap<>();
			map.put("id", d.get("id"));
			map.put("accountId", d.get("accountId"));
			map.put("status", d.get("status"));
			map.put("name", d.get("name"));
			map.put("createTime", sdf.format(d.get("createTime")));
			list.add(map);
		}
    	json.put("result", "0");
		json.put("description", "获取商家列表成功");
		json.put("list", list);
		json.put("count",dListAll.size());
		return buildReqJsonObject(json);
	}
	
	
	@RequestMapping(value = "dealAccountProduct", method = RequestMethod.POST)
	@ResponseBody
	public String dealAccountProduct() {
		JSONObject json = new JSONObject();
		if (sign == 1) {
			json.put("result", "1");
			json.put("description", "请检查参数格式是否正确或者参数是否完整");
			return buildReqJsonInteger(1, json);
		}
		// 登录认证失败
		if (sign == 2) {
			json.put("result", "2");
			json.put("description", "账号未登录");
			return buildReqJsonInteger(2, json);
		}
		
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute("MANAGER");
        if(manager == null){
        	json.put("result", "1");
			json.put("description", "账号未登陆");
			return buildReqJsonObject(json);
        }
        
		JSONObject bodyInfo = JSONObject.fromObject(bodyString);
		Map<String,Object> map = new HashMap<>();
		int status=0;
		if(bodyInfo.get("id") != null && !"".equals(bodyInfo.get("id"))) {
			map.put("id",  bodyInfo.get("id"));
		}
		if(bodyInfo.get("type") != null && !"".equals(bodyInfo.get("type"))) {
			map.put("type",  bodyInfo.get("type"));
		}
		
		Map<String,Object> para = new HashMap<>();
		if((int)map.get("type")==1){
			para.put("id",map.get("id"));
			para.put("status",1);
			status=productService.updateById(para);
		}
		if((int)map.get("type")==0){
			para.put("id",map.get("id"));
			para.put("status",2);
			status=productService.updateById(para);
		}
		
		json.put("result", "0");
		if(status>=1){
			json.put("description", "操作成功");
		}else{
			json.put("description", "操作失败");
		}
		return buildReqJsonObject(json);
	}
	
	
	
	
}
